<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>系统留言管理</title>
<script type="text/javascript">
	
	function deleteSystemMessages(){
		//获得选中数据对象
		var selectedRows=$("#messagemessageinfo").datagrid('getSelections');
		if(selectedRows.length==0){
			$.messager.alert("系统提示","请选择要删除的数据！");
			return;
		}
		var strIds=[];//要删除的序号组合
		for(var i=0;i<selectedRows.length;i++){
			strIds.push(selectedRows[i].sysmess_id);
		}
		var ids=strIds.join(",");
		$.messager.confirm("系统提示","您确认要删掉这<font color=red>"+selectedRows.length+"</font>条数据吗？",function(r){
			if(r){
				//ajax提交 delIds
				$.post("deleteSystemMessageList",{id:ids},function(result){
					if(result){
						$.messager.alert("系统提示","您已成功删除<font color=red>"+selectedRows.length+"</font>条数据！");
						$("#messagemessageinfo").datagrid("reload");
					}else{
						$.messager.alert('系统提示',"删除失败");
					}
				},"json");
			}
		});
	}
	function deleteSystemMessage(index){
		//获得选中数据对象
		$('#messagemessageinfo').datagrid('selectRow',index);// 关键在这里  
	    var selectedRow=$('#messagemessageinfo').datagrid('getSelected'); 
		if(selectedRow.length==0){
			$.messager.alert("系统提示","请选择要删除的数据！");
			return;
		}
		$.messager.confirm("系统提示","您确认要删掉这条数据吗？",function(r){
			if(r){
				//ajax提交 delIds
				$.post("deleteSystemMessage",{sysmess_id:selectedRow.sysmess_id},function(result){
					if(result==1){
						$.messager.alert("系统提示","您已成功删除这条数据！");
						$("#messagemessageinfo").datagrid("reload");
					}else{
						$.messager.alert('系统提示',"删除失败");
					}
				},"json");
			}
		});
	}
	//查询符合条件的用户
	function searchSystemMessage(){
		$('#messagemessageinfo').datagrid('load',{
			sysmess_user_name:$('#sysmess_user_name').val(),
			sysmess_content:$('#sysmess_content').val(),
			sysmess_reply:$('#sysmess_reply').val(),
		});
	}
	
	
	function formatOper(val,row,index){
		if(!row.sysmess_reply){
	        return '<a href="#" onclick="openCheckDialog('+index+')">详情</a>&nbsp;&nbsp;<a href="#" onclick="deleteSystemMessage('+index+')">删除</a>&nbsp;&nbsp;<a href="#" onclick="openReplyDialog('+index+')">回复</a>';  
		}
		else{
			return '<a href="#" onclick="openCheckDialog('+index+')">详情</a>&nbsp;&nbsp;<a href="#" onclick="deleteSystemMessage('+index+')">删除</a>';  
		}
		
	} 
	function openReplyDialog(index){
		$("#reply").dialog("open");
		$('#messagemessageinfo').datagrid('selectRow',index);// 关键在这里  
		var selectedRow=$('#messagemessageinfo').datagrid('getSelected');
		if(selectedRow.length==0){
			$.messager.alert("系统提示","请选择要回复的数据！");
			return;
		}
		
		$("#rsysmess_parentid").val(selectedRow.sysmess_id);
		$("#rsysmess_content").val("");
	}
	function resetReplyDialog(){
		$("#rsysmess_content").val("");	
	}
	function closeReplyDialog(){
		$("#reply").dialog("close");
		
	}
	//增加用户
	function saveSysMess(){
		$("#reply_fm").form("submit",{
			url:"addSystemMessage",
			onSubmit:function(){				
				if($('#rsysmess_content').val()==""){
					$.messager.alert("系统提示","请输入回复内容");
					return false;
				}
			},
			success:function(result){
				if(result==1){
					$.messager.alert("系统提示","回复成功");
					$("#reply").dialog("close");
					$("#messagemessageinfo").datagrid("reload");
				}else{
					$.messager.alert("系统提示","回复失败");
					return;
				}
			}
		});
	}
	
	function openCheckDialog(index){
		$("#check").dialog("open");
		$('#messagemessageinfo').datagrid('selectRow',index);// 关键在这里  
	    var selectedRow=$('#messagemessageinfo').datagrid('getSelected'); 	
	    if(selectedRow.length==0){
			$.messager.alert("系统提示","请选择要删除的数据！");
			return;
		}		
		$("#csysmess_user_name").val(selectedRow.sysmess_user_name);
		$("#csysmess_content").val(selectedRow.sysmess_content);
		$("#csysmess_reply").val(selectedRow.sysmess_reply);
	}
	function closeCheckDialog(){
		$("#check").dialog("close");
	}
</script>
<link rel="stylesheet" type="text/css"  href="../../easyui-1.5/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css"  href="../../easyui-1.5/themes/icon.css" />
<script type="text/javascript" src="../../easyui-1.5/jquery.min.js"></script>
<script type="text/javascript" src="../../easyui-1.5/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../easyui-1.5/locale/easyui-lang-zh_CN.js"></script>
</head>
<body style="margin:5px">
	<table id="messagemessageinfo" title="系统留言管理" class="easyui-datagrid" fitColumns="true" striped="true"
	 pagination="true" rownumbers="true" url="getSystemMessageList" fit="true" toolbar="#tb">
		<thead>
			<tr>
				<th field="cb" checkbox="true"></th>
				<th field="sysmess_id" align="center" hidden="true">ID</th>
				<th field="sysmess_user_name" width="50" align="center">留言用户</th>
				<th field="sysmess_content" width="200" align="center">留言内容</th>
				<th field="sysmess_parentid" align="center" hidden="true">父id</th>
				<th field="sysmess_time" width="50" align="center">留言时间</th>
				<th field="sysmess_user_id" align="center" hidden="true">用户id</th>		
				<th field="sysmess_reply" width="200"  align="center">回复内容</th>
				<th field="sysmess_reply_time" width="50"  align="center">回复时间</th>
				<th field="sysmess_op" width="60"  align="center" formatter="formatOper">操作</th>				
			</tr>
		</thead>
	</table>
	<div id="tb">
		<div>
		<form id="export" method="post">
		    <div>&nbsp;</div>
			&nbsp;留言用户：&nbsp;<input type="text" name="sysmess_user_name" id="sysmess_user_name" size="20"/>
			&nbsp;留言内容：&nbsp;<input type="text" name="sysmess_content" id="sysmess_content" size="60"/>
			&nbsp;回复内容：&nbsp;
			<input type="text"id="sysmess_reply" name="sysmess_reply" size="60">
			<a href="javascript:searchSystemMessage()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
			<a href="javascript:deleteSystemMessages()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除选中</a>
			<div>&nbsp;</div>
			</form>		
		</div>
	</div>
	
	<div id="reply" class="easyui-dialog" style="width: 550px;height: 400px;padding: 10px 20px"
		closed="true" buttons="#reply-buttons" title="回复留言">
		<form id="reply_fm" method="post">
		            <div>&nbsp;</div>							
					<input type="text" name="sysmess_parentid" id="rsysmess_parentid" size="50"hidden="true"/>
					<textarea name="sysmess_content" id="rsysmess_content" rows="6" cols="60"></textarea>	
		</form>
	</div>
	<div id="reply-buttons">
		<a href="javascript:saveSysMess()" class="easyui-linkbutton" iconCls="icon-ok">回复</a>
		<a href="javascript:resetReplyDialog()" class="easyui-linkbutton" iconCls="icon-reset">重置</a>
		<a href="javascript:closeReplyDialog()" class="easyui-linkbutton" iconCls="icon-cancel">取消</a>
	</div>
	
	
	<div id="check" class="easyui-dialog" style="width: 600px;height: 400px;padding: 10px 20px"
		closed="true" buttons="#check-buttons" title="用户信息详情">
		<form id="check_fm" method="post">
		            <div>&nbsp;</div>						
					&nbsp;留言用户：&nbsp;
					<input type="text" name="sysmess_user_name" id="csysmess_user_name" editable="false" class="easyui-validatebox"/>
				    <div>&nbsp;</div>
				    &nbsp;留言内容： &nbsp;
					<textarea name="sysmess_content" id="csysmess_content" editable="false" rows="3" cols="60" class="easyui-validatebox"></textarea>	
					<div>&nbsp;</div>
					&nbsp;回复内容：&nbsp;
					<textarea name="sysmess_reply" id="csysmess_reply" editable="false" rows="3" cols="60" class="easyui-validatebox"></textarea>	  
                    
		</form>
	</div>
	<div id="check-buttons">		
		<a href="javascript:closeCheckDialog()" class="easyui-linkbutton" iconCls="icon-cancel">取消</a>
	</div>
	
</body>
</html>